<?php
    class Application_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract
    {
        private $_acl = null;
        
        public function __construct(Zend_Acl $acl) {
            $this->_acl = $acl;
        }
        
        public function preDispatch(Zend_Controller_Request_Abstract $request) {
            
            $controller = $request->getControllerName();
            $action = $request->getActionName();
            
            $role = Zend_Registry::get('role');
            
            if($this->_acl->has($controller)){
                if(!$this->_acl->isAllowed($role, $controller, $action))
                {
                    $request->setControllerName('auth');
                }
            } else {
                $request->setControllerName('error')
                        ->setActionName('error');
            }
        }
        
    }
?>
